package io.renren.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import io.renren.entity.SysUserEntity;
import io.renren.utils.QueryAuthority;
import io.renren.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.entity.TrainingImplementationManagementEntity;
import io.renren.service.TrainingImplementationManagementService;
import io.renren.utils.PageUtils;
import io.renren.utils.R;


/**
 * 培训实施管理
 * 
 * @author zhangheng
 * @email zh_123shmily@163.com
 * @date 2017-07-11 17:19:09
 */
@RestController
@RequestMapping("trainingimplementationmanagement")
public class TrainingImplementationManagementController {
	@Autowired
	private TrainingImplementationManagementService trainingImplementationManagementService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("trainingimplementationmanagement:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        QueryAuthority query = new QueryAuthority(params);

		List<TrainingImplementationManagementEntity> trainingImplementationManagementList = trainingImplementationManagementService.queryList(query);
		int total = trainingImplementationManagementService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(trainingImplementationManagementList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("trainingimplementationmanagement:info")
	public R info(@PathVariable("id") Integer id){
		TrainingImplementationManagementEntity trainingImplementationManagement = trainingImplementationManagementService.queryObject(id);
		
		return R.ok().put("trainingImplementationManagement", trainingImplementationManagement);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("trainingimplementationmanagement:save")
	public R save(@RequestBody TrainingImplementationManagementEntity trainingImplementationManagement){
		SysUserEntity entity= (SysUserEntity) ShiroUtils.getSubject().getSession().getAttribute("user");
		trainingImplementationManagement.setCdate(new Date());
		trainingImplementationManagement.setCusername(entity.getUsername());
		trainingImplementationManagement.setCompanyId(entity.getCompanyId());
		trainingImplementationManagement.setDeptId(entity.getDeptNo());
		trainingImplementationManagementService.save(trainingImplementationManagement);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("trainingimplementationmanagement:update")
	public R update(@RequestBody TrainingImplementationManagementEntity trainingImplementationManagement){
		trainingImplementationManagementService.update(trainingImplementationManagement);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("trainingimplementationmanagement:delete")
	public R delete(@RequestBody Integer[] ids){
		trainingImplementationManagementService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
